package com.iafme.service.impl;

import cn.zhxu.bs.BeanSearcher;
import cn.zhxu.bs.operator.Contain;
import cn.zhxu.bs.util.MapUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iafme.dto.req.CertificateReqDTO;
import com.iafme.dto.res.CertificateResDTO;
import com.iafme.mapper.CertificateMapper;
import com.iafme.model.Certificate;
import com.iafme.service.CertificateService;
import com.systemframework.util.SearchUtl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * @author summer
 * @version 1.0
 * @date 2025/3/24 21:22
 */
@Service
@Transactional(rollbackFor = Exception.class)
@AllArgsConstructor
public class CertificateServiceImpl extends ServiceImpl<CertificateMapper, Certificate> implements CertificateService {

    private final BeanSearcher beanSearcher;


    @Override
    public Page<CertificateResDTO> lists(CertificateReqDTO certificateReqDTO) {
        Map<String, Object> build = MapUtils.builder()
                .page(certificateReqDTO.getPageNum()-1,certificateReqDTO.getPageSize())
                .field(CertificateResDTO::getName, certificateReqDTO.getName()).op(Contain.class)
                .field(CertificateResDTO::getProjectName, certificateReqDTO.getProjectName()).build();
        return SearchUtl.searchDataList(certificateReqDTO.getPageNum(),certificateReqDTO.getPageSize(),beanSearcher.search(CertificateResDTO.class,build));
    }
}
